Skip to content

TOC2: catch headers in text in output cells created using Markdown()#1394

Open
JonAnCla wants to merge 4 commits intoipython-contrib:masterfrom
JonAnCla:toc2-output-cell-markdown
Open

TOC2: catch headers in text in output cells created using Markdown()#1394
JonAnCla wants to merge 4 commits intoipython-contrib:masterfrom
JonAnCla:toc2-output-cell-markdown

Conversation

@JonAnCla
Copy link
Copy Markdown

@JonAnCla JonAnCla commented Feb 7, 2019

Make TOC2 also catch headers in text in output cells that was created using Markdown().

This allows programmatic creation of the TOC e.g. the following will now create an entry in the TOC when "run_alternative_scenario" is True

if run_alternative_scenario:
    display(Markdown('# Results from alt scenario')

Although this change makes TOC2 add headers from Markdown() text, the TOC is not automatically updated when such cells are added/changed. (You have to click the TOC2 "refresh" button to trigger an update)

Would appreciate help in getting automatic updates working!

Thanks

… using Markdown().

This allows programmatic creation of the TOC e.g. the following will now create an entry in the TOC when "run_alternative_scenario" is True

```
if run_alternative_scenario:
    display(Markdown('# Results from alt scenario')
```

Although this change makes TOC2 add headers from Markdown() text, the TOC is not automatically updated when such cells are added/changed.

Would appreciate help in getting automatic updates working!
@jcb91
Copy link
Copy Markdown
Member

jcb91 commented Feb 18, 2019

Thanks @hottwaj for the contribution. Given that this changes the default behaviour though, I think it ought to be made optional with a parameter. Could you implement that?

@JonAnCla
Copy link
Copy Markdown
Author

Hey sure I can check that out. Any thoughts on the trigger that is needed to update the TOC when you press ctrl+enter on a cell that contains Markdown? Thanks!

@jfbercher
Copy link
Copy Markdown
Member

@hottwaj Digging a little, I don't see a signal emitted when the Markdown() function is issued (nor any display function).
"Ctrl-enter" trigs the 'execute.CodeCell' event, but listening to this one in addition to 'rendered.MarkdownCell' would add some overload (table of contents would be called for any cell exec).
Perhaps could you try to fake markdown rendering by trying something like (not tried)

display(Markdown('# Results from alt scenario')
display(Javascript("Jupyter.events.trigger('rendered.MarkdownCell')"))

Otherwise I agree with @jcb91 that an option for this would be useful.

@JonAnCla
Copy link
Copy Markdown
Author

JonAnCla commented Apr 2, 2019

@jfbercher Thanks for checking that out, maybe I can look into that if it becomes more necessary - at the moment the contents generally gets re-rendered at some point whenever a few cells are executed, so I haven't found it too problematic.

I haven't found time to look into making it an optional feature, but will try to (likely timescale: several weeks at least).

Cheers

@JonAnCla
Copy link
Copy Markdown
Author

appreciate that this is 2 years later and likely this repo is not going to see more maintenance... but I finally made that minor change (added a menu option)! Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants